package xyz.jcat.web.security.annotation;

import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class PermissionSecurityConfig extends SecurityConfig {

    public static final String LOGIN_ONLY = "login_only";

    public PermissionSecurityConfig(String permission) {
        super(permission);
    }

    public static List<ConfigAttribute> loginOnly() {
        return permissions(LOGIN_ONLY);
    }

    public static List<ConfigAttribute> permissions(String permission) {
        return Arrays.asList(new PermissionSecurityConfig(permission));
    }

    public static boolean loginOnly(String permission) {
        return Objects.equals(LOGIN_ONLY, permission);
    }
}
